package apply;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import theBeans.examInfo;
import theBeans.position;
import theDaoFactory.DaoFactory;
import theDaoImpls.*;
import theDaos.*;

/**
 * Servlet implementation class showExamOptions
 */
@WebServlet("/showExamOptionsServlet")
public class showExamOptionsServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public showExamOptionsServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		/*examInfo exam=new examInfo();
		position positionLeft=new position();*/
		
		//通过查找数据库为positionLeft赋值
		int positionLeft=0;
		
		List<position> positionList=new ArrayList<position>();
		IPositionDao positionDaoInstance=DaoFactory.getPositionDaoInstance();
		positionList=positionDaoInstance.findByIfEmpty();
		
		positionLeft=positionList.size();
		System.out.println("num:"+positionLeft);
		ServletContext application=request.getServletContext();
		application.setAttribute("positionLeft", positionLeft);
		
		List<examInfo> examList=new ArrayList<examInfo>();
		//通过查找数据库为examOption赋值
		IExamInfoDao examInfoDaoInstance=DaoFactory.getExamInfoDaoInstance();
		examList=examInfoDaoInstance.findAll();
		
		for(int i=0;i<examList.size();i++)
		{
			System.out.println(examList.get(i).getEid()+"details"+examList.get(i).getDetails());
		}
		
		HttpSession session=request.getSession();
		session.setAttribute("examList", examList);
		response.sendRedirect("apply.jsp");
		
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

}
